﻿using Prism.Commands;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using ZYing.QPanel.Constants;
using ZYing.QPanel.Navs;
using ZYing.QPanel.Views;

namespace ZYing.QPanel.ViewModels
{
    public class QPanelWindowsViewModel : ViewModelBase
    {
        private readonly IRegionManager _regionManager;
        public QPanelWindowsViewModel(IRegionManager regionManager)
        {
            _regionManager = regionManager ?? throw new ArgumentNullException(nameof(regionManager));
            this.NavItems.Add(new NavItem(IconConstants.Scheduler, "调度器", typeof(Scheduler).FullName));
            this.NavItems.Add(new NavItem(IconConstants.Jobs, "任务", typeof(Views.Jobs).FullName));
            this.NavItems.Add(new NavItem(IconConstants.Triggers, "触发器", typeof(Views.Triggers).FullName));
            this.NavItems.Add(new NavItem(IconConstants.Executions, "运行中", typeof(Views.Executions).FullName));
            this.NavItems.Add(new NavItem(IconConstants.History, "历史", typeof(Views.History).FullName));
            this.NavItems.Add(new NavItem(IconConstants.Logs, "日志", typeof(Views.Logs).FullName));
            this.OpenCommand = new DelegateCommand<NavItem>(Open);
            if (this.NavItems.Count > 0) this._currentNavItem = NavItems[0];
        }
        public ObservableCollection<NavItem> NavItems { get; } = new ObservableCollection<NavItem>();
        public DelegateCommand<NavItem> OpenCommand { get; }
        public void Open(NavItem navItem)
        {
            this.CurrentNavItem = navItem;
        }
        private NavItem _currentNavItem;

        public NavItem CurrentNavItem
        {
            get { return _currentNavItem; }
            set
            {
                if (SetProperty(ref _currentNavItem, value))
                {
                    if (_currentNavItem != null)
                        _regionManager.RequestNavigate(RegionConstants.MainRegion, _currentNavItem.View);
                }
            }
        }

    }
}
